package com.blockmeta.bbs.immodule.corebean.Impl;

import android.content.Context;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.blockmeta.bbs.baselibrary.provider.SendCallBack;
import com.blockmeta.bbs.businesslibrary.arouter.RouterPath;
import com.blockmeta.bbs.immodule.corebean.IMMetaBase;
import com.blockmeta.bbs.immodule.dao.ChatMessage;

/**
 * 其他模块调用发送，需要走这一层provider转发，避免ImmetaService接口耦合
 */
@Route(path = RouterPath.IM_SENDMESSAGE_PROVIDER)
public class IMMessageSendProviderImpl implements com.blockmeta.bbs.baselibrary.provider.IMMessageSendProvider {


    @Override
    public void sendNormalMessage(final int msgType, int toId, String pText, final SendCallBack callBack) {
        imMetaBase.sendNormalMessage(msgType, toId, pText, new IMMetaBase.MessageSendCallBack() {
            @Override
            public void fail(String msg) {
                if(callBack != null){
                    callBack.fail(msg);
                }
            }

            @Override
            public void success(ChatMessage chatMessage) {
                //发送事件,用于加载
                imMetaBase.post(new IMMetaBase.Event_SendIMMessageUnCallback(chatMessage, IMMetaBase.IMMsgType.SENDED));
                if(callBack != null){
                    callBack.success(chatMessage.getUuid());
                }
            }
        });
    }

    @Override
    public void sendImageMessage(int msgType, int toId, String pText, SendCallBack callBack) {

    }

    @Override
    public void sendFileMessage(int msgType, int toId, String pText, SendCallBack callBack) {

    }

    @Override
    public void sendCustomMessage(int msgType, int toId, String pText, int subType, final SendCallBack callBack) {
        imMetaBase.sendCustomMessage(msgType, toId, pText, subType, new IMMetaBase.MessageSendCallBack() {
            @Override
            public void fail(String msg) {
                if(callBack != null){
                    callBack.fail(msg);
                }
            }

            @Override
            public void success(ChatMessage chatMessage) {
                //发送事件,用于加载
                imMetaBase.post(new IMMetaBase.Event_SendIMMessageUnCallback(chatMessage, IMMetaBase.IMMsgType.SENDED));
                if(callBack != null){
                    callBack.success(chatMessage.getUuid());
                }
            }
        });
    }



    IMMetaBase imMetaBase;
    @Override
    public void init(Context context) {
        imMetaBase = IMApplicationContext.getIMMetaService();
    }
}
